<?php

namespace Yolo\Errors\Exceptions;

use Exception;
use Yolo\Errors\ResponseError;

class YoloException extends Exception
{
    protected string $type;
    protected string $symbol;

    protected ResponseError $systemException;

    public function setSystemException(ResponseError $systemException): void
    {
        $this->systemException = $systemException;
    }

    public function getSystemException(): ResponseError
    {
        return $this->systemException;
    }

    public function setMetadata(array $metadata): void
    {
        $oldMetadata = $this->systemException->getMetadata();
        $this->systemException->setMetadata(array_merge($oldMetadata, $metadata));
    }

    public function getJson(): array
    {
        return [
            'code' => $this->systemException->getCode(),
            'message' => $this->systemException->getMessage(),
            'symbol' => $this->systemException->getSymbol(),
            'metadata' => $this->systemException->getMetadata(),
            'extra' => [
                'http' => [
                    'status' => $this->systemException->getHttpStatus(),
                ],
            ],
        ];
    }

    public function getFullJson(): array
    {
        return [
            'module' => $this->systemException->getModule(),
            'type' => $this->systemException->getType(),
            'code' => $this->systemException->getCode(),
            'message' => $this->systemException->getMessage(),
            'symbol' => $this->systemException->getSymbol(),
            'metadata' => $this->systemException->getMetadata(),
            'extra' => [
                'http' => [
                    'status' => $this->systemException->getHttpStatus(),
                ],
            ],
        ];
    }
}
